/**
 * ReportGear(2011)
 */
package com.reportgear.report.setting;

import java.awt.print.PageFormat;

import com.reportgear.report.print.Margin;
import com.reportgear.report.print.PaperSize;

/**
 * 纸张设置
 * 
 * @version 1.0 2011-4-21
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 */
public class PaperSetting {
    private PaperSize paperSize = PaperSize.PAPERSIZE_A4;
    private Margin margin = Margin.DEFAULT_MARGIN;
    private int orientation = PageFormat.PORTRAIT;

    public PaperSetting() {
        this.margin = new Margin(0.2D, 0.7D, 0.2D, 0.7D);
    }

    public PaperSetting(PaperSize paperSize, Margin margin, int orientation) {
        this.paperSize = paperSize;
        this.margin = margin;
        this.orientation = orientation;
    }

    public PaperSize getPaperSize() {
        PaperSize paperSizer = this.paperSize;

        return paperSizer == null ? PaperSize.PAPERSIZE_A4 : paperSizer;
    }

    public void setPaperSize(PaperSize paperSize) {
        this.paperSize = paperSize;
    }

    public Margin getMargin() {
        return this.margin;
    }

    public void setMargin(Margin margin) {
        this.margin = margin;
    }

    public int getOrientation() {
        return this.orientation;
    }

    public void setOrientation(int orientation) {
        this.orientation = orientation;
    }

    public String toString() {
        return "打印方向:" + this.orientation;
    }

    public PaperSetting clone() {
        try {
            PaperSetting paperSetting = (PaperSetting) super.clone();

            paperSetting.setPaperSize(this.paperSize.clone());
            paperSetting.setMargin(this.margin.clone());

            return paperSetting;
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
            return null;
        }
    }
}
